/**
 * CurdGrid对象
 * @since 1.0 <2015-6-8> SoChishun Added.
 * @since 2.0 <2015-6-11> SoChishun 重构为类对象
 * @since 2.1 <2015-6-15> SoChishun 编辑表单改为iframe方式
 * @since 2.2 <2015-7-31> SoChishun 新增treegrid支持
 */
var CurdGrid = {
    newInstance: function () {
        var obj = {
            /**
             * 对话框计数器
             */
            dialog_count: 0,
            /**
             * 默认设置
             * @type JSON
             * @since 1.0 2015-6-9 SoChishun Added.
             * @since 1.1 2015-7-31 SoChishun 新增grid_mode配置项
             */
            base_config: {
                grid_mode: 'datagrid', // 支持datagrid,treegrid
                grid_id: '#main_grid',
                grid_queryParams: '',
                grid_empty_message: '', // 如：抱歉,没有数据!
                search_dialog_id: '#dlg_search',
            },
            /**
             * 表格配置
             * @type JSON
             * @since 1.0 2015-6-8 SoChishun Added.
             * @since 1.1 <2015-7-31> SoChishun 新增showHeader选项.
             * @since 1.2 <2015-8-11> SoChishun 新增双击事件
             */
            grid_config: {height: 480, rownumbers: true, pagination: true, pageSize: 20, pageList: [10, 20, 30, 40, 50, 100], singleSelect: true, checkOnSelect: false, selectOnCheck: false, onLoadError: function () {
                    if (obj.base_config.grid_empty_message) {
                        alert(obj.base_config.grid_empty_message);
                    }
                }, onDblClickRow: function (index, row) {
                    var $a = $(".lnk_grid_edit");
                    if ($a[0]) {
                        obj.open_iframe_dialog({title: obj._replace_title_vars($a, row), icon: $a.attr('iconCls'), url: obj._replace_var_keys($a.attr('href'), row, $a.data('varReplaces'))});
                    }
                }},
            /**
             * 表格设置
             * <br />必需在set_base_config()之前执行
             * @param JSON options
             * @since 1.0 2015-6-9 SoChishun Added.
             */
            set_grid_config: function (options) {
                $.extend(this.grid_config, options);
            },
            /**
             * 基本设置
             * <br />必需在set_grid_config()之前执行
             * @param JSON options
             * @since 1.0 <2015-7-31> SoChishun Added.
             */
            set_base_config: function (options) {
                $.extend(this.base_config, options);
                if (this.base_config.grid_mode == 'treegrid') {
                    this.grid_config.pagination = false;
                    this.grid_config.idField = 'id';
                    this.grid_config.treeField = 'name';
                }
            },
            /**
             * 设置编辑对话框配置
             * @param JSON options
             * @returns JSON
             * @since 1.0 <2015-8-11> SoChishun Added.
             * @example 
             * curd_grid.set_edit_dialog_config = function (options,ifrm_id) {
             options.buttons.unshift({
             text: '导出',
             iconCls: 'icon-save',
             handler: function () {
             $('#' + ifrm_id).contents().find("form")[0].submit();
             }
             });
             }
             */
            set_edit_dialog_config: function (options, ifrm_id) {
                return options;
            },
            /**
             * 查询处理方法
             * @since 1.0 2015-6-9 SoChishun Added.
             */
            search_handler: function () {
                var data = $(this.base_config.search_dialog_id + ' form').serializeArray();
                var param = {};
                for (var i = 0; i < data.length; i++) {
                    param[data[i].name] = data[i].value;
                }
                switch (this.base_config.grid_mode) {
                    case 'treegrid':
                        $(this.base_config.grid_id).treegrid({
                            queryParams: param
                        });
                        break;
                    default:
                        $(this.base_config.grid_id).datagrid({
                            queryParams: param
                        });
                        break;
                }
            },
            /**
             * 删除记录处理方法
             * @param string url
             * @since 1.0 2015-6-9 SoChishun Added.
             * @since 2.0 2015-7-1 SoChishun 把参数url改为options, 新增confim和prompt确认逻辑 <a data-prompt-value="pass123">删除</a>
             * @since 2.1 2015-7-3 SoChishun 修正prompt取消的时候会弹出错误提示的问题
             * @since 2.2 2015-7-10 SoChishun 新增成功后调用的js方法 <a data-success-fn="show_reload_tip" />
             * @since 2.3 <2015-7-28> SoChishun 新增自定义值的键名功能 <a data-value-key="id" />
             * @since 2.4 <2015-7-31> SoChishun data-value-key属性升级为data-var-replaces属性 <a data-var-replaces='{"varid":"id","varfid":"parent_id"}' />
             * @since 2.5 <2015-8-3> SoChishun options.success方法新增data参数
             */
            delete_record_handler: function (options) {
                if (!options || !options.url) {
                    alert('方法参数无效!');
                    return;
                }
                var checks;
                switch (this.base_config.grid_mode) {
                    case 'treegrid':
                        checks = $(this.base_config.grid_id).treegrid('getChecked');
                        break;
                    default:
                        checks = $(this.base_config.grid_id).datagrid('getChecked');
                        break;
                }
                if (checks.length < 1) {
                    alert('没有选择任何记录!');
                    return false;
                }
                var config = {
                    url: '',
                    var_replaces: null,
                    confirm_message: '', // 您确定要删除{n}条记录吗?
                    prompt_text: '', // 请输入口令
                    prompt_value: '',
                    prompt_default: '',
                    success: function (data) {

                    },
                }
                $.extend(config, options);
                if (config.confirm_message && !confirm(config.confirm_message.replace('{n}', checks.length))) {
                    return;
                }
                if (config.prompt_text) {
                    var code = prompt(config.prompt_text, config.prompt_default);
                    if (null === code) {
                        return;
                    }
                    if (code != config.prompt_value) {
                        alert('输入错误!');
                        return;
                    }
                }
                var row = {}; // 不能用var row=config.var_replaces,变量引用会修改config.var_replaces
                for (var key in config.var_replaces) {
                    row[key] = '';
                }
                $(checks).each(function () {
                    for (var key in config.var_replaces) {
                        row[key] += ',' + this[config.var_replaces[key]];
                    }
                })
                for (var key in config.var_replaces) {
                    config.url = config.url.replace(key, row[key].substring(1));
                }
                this.ajax_get_process({url: config.url, success: config.success});
            },
            /**
             * 解析元素的data属性的值
             * 返回JSON值,data属性的值标准格式：data-value='{"":"","":""}', 值用单引号包含,元素键值用双引号包含(不能用单引号)
             * @param string|JSON data_value data-xxx的值
             * @param JSON def_json 默认JSON值,默认undefined
             * @returns JSON
             * @since 1.0 <2015-7-31> SoChishun Added.
             * @example <a data-var-replaces="{'varkey':'id','varid':'id','varname':'name','varfid':'parent_id'}" />
             *      <a data-var-replaces='{"varid":"extensionNumber"}' />
             */
            _parse_data_json: function (data_value, def_json) {
                if (undefined == data_value) {
                    data_value = def_json;
                } else if ('string' == typeof (data_value)) {
                    data_value = JSON.parse(data_value.replace(/'/g, '"'));
                }
                return data_value;
            },
            /**
             * 替换文本中的变量占位符
             * @param string txt 包含变量占位符的字符串
             * @param JSON row grid('getChecked').each()的数据
             * @param string|JSON var_replaces data-var-replaces的值
             * @returns string
             * @since 1.0 <2015-7-31> SoChishun Added.
             */
            _replace_var_keys: function (txt, row, var_replaces) {
                var_replaces = this._parse_data_json(var_replaces, {'varid': 'id', 'varkey': 'id'});
                for (var key in var_replaces) {
                    txt = txt.replace(key, row[var_replaces[key]]);
                }
                return txt;
            },
            /**
             * 替换标题中的变量
             * @param jQuery $a
             * @param JSON row
             * @returns string
             * @since 1.0 <2015-7-31> SoChishun Added.
             * @example <a data-title="标题 {name}" />
             */
            _replace_title_vars: function ($a, row) {
                var title = $a.data('title') ? $a.data('title') : $a.text();
                if (title.indexOf('{') > -1) {
                    for (var key in row) {
                        title = title.replace('{' + key + '}', row[key]);
                    }
                }
                return title;
            },
            /**
             * ajax普通处理
             * @param string url
             * @since 1.0 <2015-6-26> SoChishun Added.
             * @since 1.1 <2015-7-10> SoChishun 参数url改为选项形式,新增options.success选项
             * @since 1.2 <2015-8-3> SoChishun options.success方法新增data参数
             */
            ajax_get_process: function (options) {
                if (!options || !options.url) {
                    alert('[ajax_get_process] 无效参数!');
                    return;
                }
                // 显示loading
                var $grid = $(this.base_config.grid_id);
                if (!$grid.children("div.datagrid-mask").length) {
                    $('<div class="datagrid-mask" style="display:block"></div>').appendTo($grid);
                    var $msg = $('<div class="datagrid-mask-msg" style="display:block;left:50%"></div>').html('正在处理...').appendTo($grid);
                    $msg._outerHeight(40);
                    $msg.css({marginLeft: (-$msg.outerWidth() / 2), lineHeight: ($msg.height() + "px")});
                }
                $.ajax({
                    type: 'GET',
                    dataType: 'JSON',
                    url: options.url,
                    success: function (msg) {
                        $grid.children("div.datagrid-mask-msg, div.datagrid-mask").remove();
                        if (msg.status) {
                            options.success(msg);
                            obj.reload_grid();
                        } else {
                            alert(msg.info);
                        }
                    },
                    error: function () {
                        $grid.children("div.datagrid-mask-msg, div.datagrid-mask").remove();
                        $.messager.alert('警告', '抱歉,操作提交失败,请联系管理员!', 'warning');
                    },
                });
            },
            /**
             * 打开查询对话框前的操作
             * @since 1.0 <2015-6-30> SoChishun Added.
             */
            before_search_dialog: function () {
            },
            /**
             * curd按钮点击设置
             * @since 1.0 2015-6-10 SoChishun Added.
             * @since 1.1 <2015-8-3> SoChishun 新增刷新按钮
             */
            link_click_handler: function () {
                // 刷新按钮
                $('.lnk_grid_reload').click(function () {
                    obj.reload_grid();
                    return false;
                });
                // 查询按钮
                $(".lnk_grid_search").click(function () {
                    return obj.lnk_search_event(this);
                });
                // 新增按钮
                $(".lnk_grid_add").click(function () {
                    return obj.lnk_add_event(this);
                });
                // 编辑按钮
                $(".lnk_grid_edit").click(function () {
                    return obj.lnk_edit_event(this);
                });
                // 删除按钮
                $(".lnk_grid_remove").click(function () {
                    return obj.lnk_remove_event(this);
                });
                // 普通后台操作按钮
                $('.lnk_grid_process').click(function () {
                    return obj.lnk_process_event(this);
                });
                // 普通展示按钮
                $('.lnk_grid_info').click(function () {
                    return obj.lnk_info_event(this);
                })
            },
            /**
             * 查询事件
             * @param element a
             * @since 1.0 <2015-7-8> SoChishun Added.
             */
            lnk_search_event: function (a) {
                this.before_search_dialog();
                this.open_search_dialog();
                return false;
            },
            /**
             * 添加事件
             * @param element a
             * @since 1.0 <2015-7-8> SoChishun Added.
             * @since 1.1 <2015-7-25> SoChishun 新增图标同步功能.
             */
            lnk_add_event: function (a) {
                var $a = $(a);
                this.open_iframe_dialog({title: $a.text(), icon: $a.attr('iconCls'), url: $a.attr('href')});
                return false;
            },
            /**
             * 编辑事件
             * @param element a
             * @since 1.0 <2015-7-8> SoChishun Added.
             * @since 1.1 <2015-7-10> SoChishun 取消多选只能编辑第一条的限制
             * @since 1.2 <2015-7-25> SoChishun 新增图标同步功能.
             * @since 1.3 <2015-7-28> SoChishun 新增自定义值的键名功能 <a data-value-key="id" />
             * @since 1.4 <2015-7-31> SoChishun data-value-key属性升级为data-var-replaces属性 <a data-var-replaces='{"varid":"id","varfid":"parent_id"}' />
             *                                      新增data-title变量解析功能 <a data-title="编辑 {name}" />
             * @since 1.5 <2015-8-4> SoChishun 新增data-window-model属性 <a data-window-model="single" />
             */
            lnk_edit_event: function (a) {
                var checks;
                switch (this.base_config.grid_mode) {
                    case 'treegrid':
                        checks = $(this.base_config.grid_id).treegrid('getChecked');
                        break;
                    default:
                        checks = $(this.base_config.grid_id).datagrid('getChecked');
                        break;
                }
                if (checks.length < 1) {
                    alert('没有选择任何记录!');
                    return false;
                }
                var $a = $(a);
                if ('single' == $a.data('windowMode')) {
                    var sids = '';
                    $(checks).each(function () {
                        if (sids) {
                            sids += ',';
                        }
                        sids += this['id'];
                    })
                    obj.open_iframe_dialog({title: $a.data('title') ? $a.data('title') : $a.text(), icon: $a.attr('iconCls'), url: obj._replace_var_keys($a.attr('href'), {id: sids}, $a.data('varReplaces'))});
                } else {
                    if (checks.length > 1) {
                        alert('您选择了' + checks.length + '条记录进行编辑.\n(弹窗太多会使浏览器变卡,请及时关闭无用的弹窗.)');
                    }
                    $(checks).each(function () {
                        obj.open_iframe_dialog({title: obj._replace_title_vars($a, this), icon: $a.attr('iconCls'), url: obj._replace_var_keys($a.attr('href'), this, $a.data('varReplaces'))});
                    })
                }
                return false;
            },
            /**
             * 删除事件
             * @param element a
             * @since 1.0 <2015-7-8> SoChishun Added.
             * @since 1.1 <2015-7-10> SoChishun 新增成功后调用的js方法 <a data-success-fn="show_reload_tip" />
             * @since 1.2 <2015-7-28> SoChishun 新增自定义值的键名功能 <a data-value-key="id" />
             * @since 1.3 <2015-7-31> SoChishun data-value-key属性升级为data-var-replaces属性 <a data-var-replaces='{"varid":"id","varfid":"parent_id"}' />
             * @since 1.4 <2015-8-3> SoChishun data-success-fn新增data参数,data格式;{status:false,info:msg}
             *                          如：function delete_task_tip(data){alert(data.info);}
             *                           <a data-success-fn="delete_task_tip(data)">删除</a>
             */
            lnk_remove_event: function (a) {
                var $a = $(a);
                var options = {
                    url: $a.attr('href'),
                    var_replaces: obj._parse_data_json($a.data('varReplaces'), {'varid': 'id', 'varkey': 'id'}),
                    confirm_message: $a.data('confirmMessage'), // 您确定要删除这{n}条记录吗?
                    prompt_text: $a.data('promptText'), // 请输入口令
                    prompt_value: $a.data('promptValue'),
                    prompt_default: $a.data('promptDefault'),
                    success: function (data) {
                        var success_fn = $a.data('successFn');
                        if (success_fn) {
                            if (success_fn.indexOf('(') < 0) {
                                success_fn += '(' + (data ? JSON.stringify(data) : '') + ')';
                            }
                            eval(success_fn);
                        }
                    }
                }
                if (!options.confirm_message) {
                    options.confirm_message = '您确定要删除这{n}条记录吗?';
                }
                if (options.prompt_value && !options.prompt_text) {
                    options.prompt_text = '请输入口令：';
                }
                this.delete_record_handler(options);
                return false;
            },
            /**
             * 后台处理事件
             * <br />与lnk_remove_event不同在于不需要勾选grid行
             * @param element a
             * @since 1.0 <2015-7-8> SoChishun Added.
             * @since 1.0 <2015-7-10> SoChishun 新增成功后调用的js方法 <a data-success-fn="show_reload_tip" />
             */
            lnk_process_event: function (a) {
                var $a = $(a);
                obj.ajax_get_process({url: $a.attr('href'), success: function () {
                        var success_fn = $a.data('successFn');
                        if (success_fn) {
                            if (success_fn.indexOf('(') < 0) {
                                success_fn += '()';
                            }
                            eval(success_fn);
                        }
                    }});
                return false;
            },
            /**
             * 信息事件
             * <br />与lnk_add_event弹窗类似，但没有按钮组，纯粹展示页面
             * @param element a
             * @since 1.0 <2015-7-8> SoChishun Added.
             * @since 1.1 <2015-7-10> SoChishun 新增data-need-checking参数 <a data-need-checking="true" />
             * @since 1.2 <2015-7-24> SoChishun 新增size参数和noheader参数 <a data-size='{"width":600}' data-noheader="true" />
             * @since 1.3 <2015-7-25> SoChishun 新增图标同步功能.
             * @since 1.4 <2015-7-28> SoChishun 新增自定义值的键名功能 <a data-value-key="id" />
             * @since 1.5 <2015-7-31> SoChishun data-value-key属性升级为data-var-replaces属性 <a data-var-replaces='{"varid":"id","varfid":"parent_id"}' />
             *                                      新增data-title变量解析功能 <a data-title="编辑 {name}" />
             * @example <a href="{:U('Statics/call_history_lite','queue='.$key)}" class="lnk_info" data-size='{"width":580,"height":540}' data-noheader="true" data-title="{$key}通话详单">[通话详单]</a>
             */
            lnk_info_event: function (a) {
                var $a = $(a);
                try {
                    var size = this._parse_data_json($a.data('size'));
                } catch (e) {
                    alert('lnk_info_event: ' + e.message);
                    return false;
                }
                var noheader = $a.data('noheader');
                var url = $a.attr('href');
                var needChecking = $a.data('needChecking');
                if (needChecking) {
                    var checks;
                    switch (this.base_config.grid_mode) {
                        case 'treegrid':
                            checks = $(this.base_config.grid_id).treegrid('getChecked');
                            break;
                        default:
                            checks = $(this.base_config.grid_id).datagrid('getChecked');
                            break;
                    }
                    if (checks.length < 1) {
                        alert('没有选择任何记录!');
                        return false;
                    }
                    $(checks).each(function () {
                        obj.open_iframe_dialog({title: obj._replace_title_vars($a, this), icon: $a.attr('iconCls'), noheader: noheader, url: obj._replace_var_keys(url, this, $a.data('varReplaces'))}, size);
                    })
                } else {
                    var title = $a.data('title') ? $a.data('title') : $a.text();
                    this.open_iframe_dialog({title: title, icon: $a.attr('iconCls'), noheader: noheader, url: url, buttons: []}, size);
                }
                return false;
            },
            /**
             * 初始化
             * @param JSON options
             * @since 1.0 2015-6-8 SoChishun Added.
             */
            init: function (options) {
                if (undefined != options) {
                    $.extend(this.base_config, options);
                }
                // 初始化grid
                if (this.base_config.grid_id && this.grid_config) {
                    var $grid = $(this.base_config.grid_id);
                    if (!this.grid_config.url) {
                        this.grid_config.url = $grid.data('url');
                    }
                    // 读取grid中的data-queryParams
                    if ($grid.data('queryParams')) {
                        this.grid_config.queryParams = $.parseJSON('{' + $grid.data('queryParams') + '}');
                    }
                    // 读取隐藏配置 datagrid_queryParams_id
                    if (this.base_config.grid_queryParams) {
                        this.grid_config.queryParams = $.parseJSON('{' + $(this.base_config.grid_queryParams).html() + '}');
                    }
                    //TODO: 设置pagination:true的时候,会触发重复加载数据源的BUG,待解决
                    switch (this.base_config.grid_mode) {
                        case 'treegrid':
                            $grid.treegrid(this.grid_config);
                            break;
                        default:
                            $grid.datagrid(this.grid_config);
                            break;
                    }
                }
                // 初始化按钮点击事件
                this.link_click_handler();
            },
            /**
             * 刷新表格
             * @param object param
             * @since 1.0 <2015-7-6> SoChishun Added.
             */
            reload_grid: function (param) {
                switch (this.base_config.grid_mode) {
                    case 'treegrid':
                        if (param) {
                            $(this.base_config.grid_id).treegrid({queryParams: param});
                        } else {
                            $(this.base_config.grid_id).treegrid('reload');
                        }
                        break;
                    default:
                        if (param) {
                            $(this.base_config.grid_id).datagrid({queryParams: param});
                        } else {
                            $(this.base_config.grid_id).datagrid('reload');
                        }
                        break;
                }
            },
            /**
             * 打开新增/编辑对话框
             * @param string url
             * @since 1.0 <2015-6-9> SoChishun Added.
             * @since 2.0 <2015-6-16> SoChishun 重构为iframe
             * @since 2.1 <2015-6-25> SoChishun 新增onClose方法,释放资源
             * @since 2.2 <2015-7-24> SoChishun 新增size参数和noheader参数
             * @since 2.3 <2015-7-31> SoChishun 新增size包含width和height时,对iframe的load事件不再重置尺寸的判断
             * @since 2.4 <2015-8-11> SoChishun 新增set_edit_dialog_config()方法，用于修改按钮
             */
            open_iframe_dialog: function (param, size) {
                if (!param || !param.url) {
                    alert('对话框参数有误!');
                    return;
                }
                var ifrm_id = 'editform_' + this.dialog_count;
                this.dialog_count++;

                var _param = {url: '', title: '编辑表单', icon: 'icon-edit', buttons: [{
                            text: '保存',
                            iconCls: 'icon-ok',
                            handler: function () {
                                // 子页面要有item_form实例对象
                                if (undefined == $('#' + ifrm_id)[0].contentWindow.item_form) {
                                    alert('未设置表单提交处理方法!');
                                } else {
                                    $('#' + ifrm_id)[0].contentWindow.item_form.submit(ifrm_id);
                                }

                            }
                        }, {
                            text: '重置',
                            iconCls: 'icon-undo',
                            handler: function () {
                                $('#' + ifrm_id).contents().find("form").form('reset');
                            }
                        }, {
                            text: '取消',
                            iconCls: 'icon-cancel',
                            handler: function () {
                                obj.close_iframe_dialog(ifrm_id);
                            }
                        }]};
                $.extend(_param, param);
                this.set_edit_dialog_config(_param, ifrm_id);
                var config = {
                    title: _param.title,
                    iconCls: _param.icon,
                    noheader: _param.noheader,
                    resizable: true,
                    onClose: function () {
                        var $dlg = $('#' + ifrm_id).attr('src', "about:blank").parent();
                        $dlg.next().remove();
                        $dlg.remove();
                        $dlg = null;
                    },
                    buttons: _param.buttons,
                };
                if (size) {
                    if (size.width) {
                        config.width = size.width;
                    }
                    if (size.height) {
                        config.height = size.height;
                    }
                }
                $('<iframe id="' + ifrm_id + '" name="' + ifrm_id + '"></iframe>').dialog(config);
                $('#' + ifrm_id).attr('src', _param.url).load(function () {
                    if (!size || !size.width || !size.height) {
                        obj.resize_iframe_dialog(ifrm_id, size);
                    }
                });
            },
            /**
             * 关闭IFrame对话框
             * @param string ifrm_id
             * @since 1.0 <2015-6-16> SoChishun Added.
             */
            close_iframe_dialog: function (ifrm_id, refresh) {
                var $dlg = $('#' + ifrm_id).attr('src', "about:blank").dialog('close').parent();
                $dlg.next().remove();
                $dlg.remove();
                $dlg = null;
                if (refresh) {
                    switch (this.base_config.grid_mode) {
                        case 'treegrid':
                            $(this.base_config.grid_id).treegrid('reload');
                            break;
                        default:
                            $(this.base_config.grid_id).datagrid('reload');
                            break;
                    }
                }
            },
            /**
             * 重设IFrame对话框尺寸
             * @param string ifrm_id
             * @param object o_size
             * @since 1.0 <2015-6-16> SoChishun Added.
             * @since 1.1 <2015-6-25> SoChishun 新增size
             * @example window.parent.curd_grid.resize_iframe_dialog(window.name,{width:332});
             */
            resize_iframe_dialog: function (ifrm_id, size) {
                var $ifrm = $('#' + ifrm_id);
                var _size = {
                    height: $ifrm.contents().find("body").height(),
                    width: $ifrm.contents().find("body").width()
                };
                if (size) {
                    $.extend(_size, size);
                }
                $ifrm.dialog({height: _size.height + 100, width: _size.width + 20});
            },
            /**
             * 打开查询对话框
             * @since 1.0 <2015-6-9> SoChishun Added
             * @since 1.1 <2015-6-30> SoChishun 新增导出按钮功能(在form新增data-export-url属性即可)
             */
            open_search_dialog: function () {
                var config = {
                    title: '搜索',
                    iconCls: 'icon-search',
                    buttons: [{
                            text: '确定',
                            iconCls: 'icon-ok',
                            handler: function () {
                                obj.search_handler();
                                $(obj.base_config.search_dialog_id).dialog('close');
                            }
                        }, {
                            text: '重置',
                            iconCls: 'icon-undo',
                            handler: function () {
                                $(obj.base_config.search_dialog_id + ' form').form('reset');
                            }
                        }, {
                            text: '取消',
                            iconCls: 'icon-cancel',
                            handler: function () {
                                $(obj.base_config.search_dialog_id).dialog('close');
                            }
                        }]
                };
                var $form = $(this.base_config.search_dialog_id).find("form");
                if ($form.data('exportUrl')) {
                    config.buttons.splice(2, 0, {
                        text: '导出',
                        iconCls: 'icon-save',
                        handler: function () {
                            var action = $form.attr('action');
                            $form.attr('action', $form.data('exportUrl')).submit();
                            $form.attr('action', action);
                        }
                    });
                }
                $(this.base_config.search_dialog_id).dialog(config);
            },
        };
        return obj;
    }
}